package com.example.yls.demoa;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by yls on 2018/4/25.
 */

public class BitmapImageCache implements ImageLoader.ImageCache {

    private LruCache<String,Bitmap> stringBitmapLruCache;
    private int MAXSIZE =10*1024*1024;
    public BitmapImageCache(){
        stringBitmapLruCache = new LruCache<String, Bitmap>(MAXSIZE){
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes()*bitmap.getHeight();
            }
        };
    }
    public Bitmap getBitmap(String s) {
        Log.e("BitmapCache","get"+s);
        return stringBitmapLruCache.get(s);
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        Log.e("BitmapCache","put"+s);
        stringBitmapLruCache.put(s,bitmap);
    }
}
